#include <stdlib.h>
#include <pthread.h>
#include <stdint.h>
#include <sys/select.h>
#include <sys/socket.h>
#include <sys/un.h>

#define NIT_SHORT_NAMES
#include <nit/socket.h>

#include "tp.h"
#include "tr.h"

void
echo(Nit_joint *in, Nit_joint *out)
{
        Blu_trad trad;
	Blu_tpad ad = {
		.spc = 0.2,
		.chunk = 2
	};

	blu_trad_init(&trad, 0);

	while (1) {
		switch (blu_tr(in, &trad)) {
		case NIT_JOIN_NONE:
			break;
		case NIT_JOIN_CLOSED:
		case NIT_JOIN_ERROR:
			return;
		case NIT_JOIN_OK:
			ad.bytes = trad.buf;
			ad.size = trad.msg;

			blu_tp(NULL, out, &ad, NULL);

			break;
		}
	}
}

int
main(int argc, char *argv[])
{
	Nit_joiner *jnr_out = joiner_new("blushd/out");
	Nit_joiner *jnr_in = joiner_new("blushd/in");
	Nit_joint *jnt_out = joiner_accept(jnr_out);
	Nit_joint *jnt_in = joiner_accept(jnr_in);

	blu_tr_rate_change(jnt_in, 1);
	echo(jnt_in, jnt_out);
}
